package com.zhibang.util;

import org.apache.shiro.crypto.hash.SimpleHash;

import java.util.Random;

/**
 * 加密工具类
 **/
public class SHAUtil {
    public static void main(String[] args) {
        System.out.println(sha256Pwd("123","q3"));
    }

    // 对明文密码加密
    public static String sha256Pwd(String oldPwd,String salt){
        return new SimpleHash("sha-256",oldPwd,salt,100).toString();
    }
    static Random r = new Random();

    public static String getSalt(){
        String str = "qwertyuiopasdfghjklzxcvbnm,1234567890-=@#$%^&*()";
        // 随机取出6个字符作为盐
        char[] cs = new char[6];
        for (int i = 0; i < cs.length; i++) {
            int index = r.nextInt(str.length());
            cs[i] = str.charAt(index);
        }
        return new String(cs);
    }
}
